﻿//2013-12-20
using System;
using System.Collections;
using PSS.DAL.SetManage.BasicData;
using PSS.Entity;
using PSS.Entity.SetManage.BasicData;
using PSS.Utility;

namespace PSS.BLL.SetManage.BasicData
{
    public class AccountBLL
    {
        private readonly AccountDAL _dal=new AccountDAL();

        public string GetAccountList(Pagination qcmodel)
        {
            var total = _dal.GetTotal();
            var list = _dal.GetAccountList(qcmodel);
            return JsonHelper.Encode(total, list);
        }
        public string GetAccountListByCombobox()
        {
            return JsonHelper.Encode(_dal.GetAccountListByCombobox());
        }
        public bool ModifyAccount(string data)
        {
            var model = new AccountEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.AccountId = new Guid(row["AccountId"].ToString());
                model.AccountCode = row["AccountCode"].ToString();
                model.AccountName = row["AccountName"].ToString();
                model.BalanceDate = Convert.ToDateTime(row["BalanceDate"].ToString());
                model.AccountBalance = Convert.ToDecimal(row["AccountBalance"].ToString());
                model.AccountType = Convert.ToInt32(row["AccountType"].ToString());
            }
            return _dal.ModifyAccount(model);
        }
        public bool AddAccount(string data)
        {
            var model = new AccountEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.AccountId = Guid.NewGuid();
                model.AccountCode = row["AccountCode"].ToString();
                model.AccountName = row["AccountName"].ToString();
                model.BalanceDate = Convert.ToDateTime(row["BalanceDate"].ToString());
                model.AccountBalance = Convert.ToDecimal(row["AccountBalance"].ToString());
                model.AccountType = Convert.ToInt32(row["AccountType"].ToString());
            }
            return _dal.AddAccount(model);
        }
        public string GetAccountInfo(string id)
        {
            return JsonHelper.Encode(_dal.GetAccountInfo(id));
        }
        public bool RemoveAccount(string id)
        {
            return _dal.RemoveAccount(id);
        }
    }
}
